package com.weasel.weixin.servlet;

import com.weasel.weixin.commons.message.WeixinPostEventXmlMessageHandlerRouter;
import com.weasel.weixin.commons.message.bean.WeixinPostEventXmlMessage;
import com.weasel.weixin.commons.message.handler.*;
import org.apache.commons.io.FileUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;

/**
 * Created by Dylan on 2015/9/28.
 */
public class WeixinPostEventXmlMessageServlet extends HttpServlet {


    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setContentType("text/html;charset=utf-8");
        response.setStatus(HttpServletResponse.SC_OK);


        WeixinPostEventXmlMessage message = WeixinPostEventXmlMessage.fromWeixinPostInputSteam(request.getInputStream());

        new WeixinPostEventXmlMessageHandlerRouter(message).addHandler(new WeixinPostClickEventXmlMassageHandler() {
            @Override
            protected void handler(WeixinPostEventXmlMessage message) {
                System.out.println("用户点击定义菜单拉取消息");
            }
        }).addHandler(new WeixinPostLocationEventXmlMassageHandler() {
            @Override
            protected void handler(WeixinPostEventXmlMessage message) {
                System.out.println("用户上传了地理位置");
            }
        }).addHandler(new WeixinPostScanEventXmlMassageHandler() {
            @Override
            protected void handler(WeixinPostEventXmlMessage message) {
                System.out.println("用户重复关注了公众号");
            }
        }).addHandler(new WeixinPostUnSubscribeEventXmlMassageHandler() {
            @Override
            protected void handler(WeixinPostEventXmlMessage message) {
                System.out.println("用户取消了关注公众号");
            }
        }).addHandler(new WeixinPostSubscribeEventXmlMassageHandler() {
            @Override
            protected void handler(WeixinPostEventXmlMessage message) {
                System.out.println("用户关注了公众号");
            }
        }).addHandler(new WeixinPostViewEventXmlMassageHandler() {
            @Override
            protected void handler(WeixinPostEventXmlMessage message) {
                System.out.println("用户点击了类型为view的算定义菜单");
            }
        }).handler();

    }
}
